package com.woniuxy.charin.mapper;

import com.woniuxy.charin.model.entity.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author KOO
* @description 针对表【permission】的数据库操作Mapper
* @createDate 2024-12-26 16:45:32
* @Entity com.woniuxy.charin.model.entity.Permission
*/
public interface PermissionMapper extends BaseMapper<Permission> {

    List<Permission> selectPermissionByUser(Long userId);


    // 根据角色ID获取权限ID列表
    @Select("SELECT permission_id FROM role_permission WHERE role_id = #{roleId}")
    List<Integer> getPermissionIdByRole(Integer roleId);

@Delete("DELETE FROM role_permission WHERE role_id = #{roleId}")
    void deleteByRole(Long roleId);

    @Insert("<script>" +
            "INSERT INTO role_permission (role_id, permission_id) VALUES " +
            "<foreach collection='permissionIds' item='permissionId' separator=','>" +
            "(#{roleId}, #{permissionId})" +
            "</foreach>" +
            "</script>")
    void batchInsert(@Param("roleId") Long roleId, @Param("permissionIds") List<Integer> permissionIds);
}




